# coding:utf-8
class Admin::ProgramsController < AdminController

  set_tab :programs
  before_filter :setup, only: [:index]

  respond_to :html, :json

  def index
    @programs = Program.includes(:television, :city_channel).
                where(["city_channels.city_id = ?",params[:city_id]]).
                order('city_channel_id ASC, sid ASC')

    @ways << params[:city_name]   
    eval %{set_tab :program_#{params[:city_id]}, :sub_nav}
  end

  def new
    @program = Program.new
    respond_to do |format|
      format.js
    end
  end

  def edit
    @program = Program.find params[:id]
  end

  def create
    @program = Program.new(params[:program])
    render :action => :new unless @program.save
  end

  def update
    @program = Program.find params[:id]
    render :action => :edit unless @program.update_attributes(params[:program])
  end

  def destroy
    @program = Program.find params[:id]
    @program.destroy
  end

  private

  def setup
    @ways = ["电台节目","节目管理"]
    @left_panel = "admin/programs/left_panel"
  end

end
